﻿using System.IO;
using System.Text;

namespace CSVideoUploader.IO
{
    /// <summary>
    /// 封装流的写入操作
    /// </summary>
    class MyStreamWriter
    {
        private Stream stream;

        public MyStreamWriter(Stream stream)
        {
            this.stream = stream;
        }

        /// <summary>
        /// 写入字节数组
        /// </summary>
        /// <param name="buffer"></param>
        public void WriteBytes(byte[] buffer)
        {
            // 每次都要写offset和count烦不烦！？
            stream.Write(buffer, 0, buffer.Length);
        }

        /// <summary>
        /// 写入字节数组
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        public void WriteBytes(byte[] buffer, int offset, int length)
        {
            stream.Write(buffer, offset, length);
        }

        public void WriteString(string str, Encoding enc)
        {
            // 写入字符串
            WriteBytes(enc.GetBytes(str));
        }

        public void Flush()
        {
            stream.Flush();
        }

        public void Close()
        {
            stream.Close();
        }
    }
}
